Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UNIX epoch <-> TIMESTAMP conversion functions #330

Merged
merged 3 commits into from
Jan 25, 2021

Conversation

alancai98
Copy link
Member

@alancai98 alancai98 commented Nov 20, 2020

Adds functions to convert from UNIX epoch to TIMESTAMP and TIMESTAMP to UNIX epoch. Largely follows MySQL's variants: FROM_UNIXTIME and UNIX_TIMESTAMP.

Still might need discussion on:

  • Better names for the functions. I just followed MySQL's convention given that I couldn't find similar functions in other DBMS and SQL-92 standard. Perhaps UNIX_TO_TIMESTAMP and TIMSTAMP_TO_UNIX would be better?
  • Supporting a format argument when converting UNIX epoch -> TIMESTAMP. This is an additional argument in MySQL's version, but this may be better served as its own function.
  • Datatype input for UNIX epoch -> TIMESTAMP currently is just a numeric value. Do we want to allow for strings (e.g. from_unixtime("1234567890"))?
  • Datatype to support for UNIX epochs? I largely followed MySQL's FROM_UNIXTIME which uses decimal depending on if the timestamp had fractional seconds, integer otherwise.
  • Some edge cases, namely: 1. What should we do when given a UNIX epoch to convert less than 0? 2. What do we do when given a timestamp before '1970-01-01 00:00:01.000000' UTC? (currently return 0)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alancai98 alancai98 self-assigned this Nov 20, 2020
@alancai98 alancai98 linked an issue Nov 20, 2020 that may be closed by this pull request
@alancai98
Copy link
Member Author

New commit removes the negative unix epoch / timestamp before the last epoch restriction and updates tests + docs accordingly. Also adds UNIX_TIMESTAMP and FROM_UNIXTIME entries to BuiltinFunctions.md.

@codecov-io
Copy link

codecov-io commented Dec 24, 2020

Codecov Report

Merging #330 (f9ff9d5) into master (2264117) will increase coverage by 0.03%.
The diff coverage is 95.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #330      +/-   ##
============================================
+ Coverage     79.58%   79.61%   +0.03%     
- Complexity     1190     1197       +7     
============================================
  Files           157      159       +2     
  Lines          9371     9391      +20     
  Branches       1526     1527       +1     
============================================
+ Hits           7458     7477      +19     
- Misses         1472     1473       +1     
  Partials        441      441              
Flag Coverage Δ Complexity Δ
CLI 0.00% <ø> (ø) 0.00 <ø> (ø)
EXAMPLES 0.00% <ø> (ø) 0.00 <ø> (ø)
LANG 85.27% <95.23%> (+0.02%) 0.00 <7.00> (ø)
PTS 100.00% <ø> (ø) 0.00 <ø> (ø)
TEST_SCRIPT 79.68% <ø> (ø) 0.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...g/src/org/partiql/lang/eval/ExprValueExtensions.kt 81.13% <50.00%> (-0.40%) 0.00 <0.00> (ø)
...org/partiql/lang/eval/builtins/BuiltinFunctions.kt 95.12% <100.00%> (+0.25%) 0.00 <0.00> (ø)
...partiql/lang/eval/builtins/FromUnixTimeFunction.kt 100.00% <100.00%> (ø) 2.00 <2.00> (?)
...artiql/lang/eval/builtins/UnixTimestampFunction.kt 100.00% <100.00%> (ø) 5.00 <5.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2264117...f9ff9d5. Read the comment docs.

@alancai98 alancai98 merged commit 0496038 into master Jan 25, 2021
@alancai98 alancai98 deleted the unix-epoch-timstamp-functions branch January 25, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support conversion between UNIX epoch and TIMESTAMP
3 participants